﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.Center
{
    /// <summary>
    /// 领导班子
    /// </summary>
    public class PartyOrgLeader : EntityBase
    {
        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string LoginID { get; set; }

        /// <summary>
        /// 职务（书记，副书记，委员）－系统参数
        /// </summary>
        public string PostCategory { get; set; }

        /// <summary>
        /// 职位
        /// </summary>
        public string Post { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int OrderNo { get; set; }

        /// <summary>
        /// 创建用户
        /// </summary>
        public string CreateBy { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }

        /// <summary>
        /// 修改用户
        /// </summary>
        public string ModifyBy { get; set; }

        /// <summary>
        /// 简介
        /// </summary>
        public string Introduction { get; set; }

        public static DataSet GetGridData(int pageIndex, int pageSize,string branchId)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "branchId",Value = branchId}
            };


            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  leader.ID,leader.BranchID,UserName,PostCategory,leader.Post,leader.OrderNo,DDicMemberName as PostCategoryName,member.ImageUrl
                        from tblpartyorgleader leader
                        left join tblpartyorgmember member on leader.LoginID=member.LoginID
                        left join tbldatadictionary ddic on DDicType='ZHDJ.OrgLeader.PostCategory' and DDicMember=PostCategory
                        where leader.BranchID=?branchId ");

            sb.Append(" order by leader.OrderNo desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
    }
}
